class Player{
  constructor(name){
    this.name = name
  }
}

class Game {
  constructor(name){
    this.name = name
  }

  play(p, o){
    console.log(p.name, o);
  }
}

class Mediator {
  constructor(players, game){
    this.players = players
    this.game = game
  }

  static createRoom(pA, pB, g){
    console.log('创建了一个游戏房间！');
    console.log('玩家为：',pA.name,'和',pB.name);
    console.log('游戏名称：', g.name);
    return new Mediator([pA, pB], g)
  }

  play(player, operate){
    this.game.play(player, operate)
  }

  over(pA){
    console.log('游戏结束：', pA.name + 'is winner!');
  }
}

const pA = new Player('小明')
const pB = new Player('小红')

const game = new Game('五子棋')
const room = Mediator.createRoom(pA, pB, game)

room.play(pA, '下了一步棋')
room.play(pB, '下了一步棋')
room.play(pA, '下了一步棋')
room.play(pB, '下了一步棋')

room.over(pA)
